/**
 * ************************************************************************
 *
 * @file    SrecCat.c
 * @brief   调用SrecCat函数
 * @author  负号科技(fuhaokj@foxmail.com)
 * @version 0.1
 * @date    2024-08-22
 *
 * ************************************************************************
 *   __       _                 _    _
 *  / _|     | |               | |  (_)
 * | |_ _   _| |__   __ _  ___ | | ___
 * |  _| | | | '_ \ / _` |/ _ \| |/ / |
 * | | | |_| | | | | (_| | (_) |   <| |
 * |_|  \__,_|_| |_|\__,_|\___/|_|\_\ |
 *                                 _/ |
 *                                |__/
 *
 * @copyright Copyright (c) 2024 负号科技
 * For study and research only, no reprinting
 * ************************************************************************
 */
#include "SrecCat.h"
#include <stdio.h>
#include <stdlib.h>
#include "log.h"

/**
 * @brief   将Hex文件转换为BIN文件
 * @param   SrecCatPath SrecCat路径
 * @param   HexPath     Hex文件路径
 * @param   offset      偏移地址
 * @param   BinPath     bin文件保存路径
 * @date    2024-08-22
 *
 */
void SrecCat_HexToBin(char *SrecCatPath, char *HexPath, char *offset, char *BinPath)
{
    char cmd[256];
    sprintf(cmd, "%s %s -intel -offset -%s -o %s -binary", SrecCatPath, HexPath, offset, BinPath);
    LOG_info("%s\n", cmd);
    system(cmd);
}

/**
 * @brief   将BIN文件转换为Hex文件
 * @param   SrecCatPath SrecCat路径
 * @param   BinPath     Bin文件路径
 * @param   offset      偏移地址
 * @param   HexPath     Hex文件保存路径
 * @date    2024-08-22
 *
 */
void SrecCat_BinToHex(char *SrecCatPath, char *BinPath, char *offset, char *HexPath)
{
    char cmd[256];
    sprintf(cmd, "%s %s -binary -offset -%s -o %s -intel", SrecCatPath, BinPath, offset, HexPath);
    LOG_info("%s\n", cmd);
    system(cmd);
}

/**
 * @brief   合并Bin文件
 * @param   SrecCatPath 参数描述
 * @param   Bin1Path    参数描述
 * @param   Bin1offset  参数描述
 * @param   Bin2Path    参数描述
 * @param   Bin2offset  参数描述
 * @param   MergeBin    参数描述
 * @date    2024-08-22
 *
 */
void SrecCat_MergeBin(char *SrecCatPath, char *Bin1Path, char *Bin1offset, char *Bin2Path, char *Bin2offset, char *MergeBin)
{
    char cmd[256];
    sprintf(cmd, "%s %s -binary -offset -%s %s -binary -offset -%s -o %s -binary", SrecCatPath, Bin1Path, Bin1offset, Bin2Path, Bin2offset, MergeBin);
    LOG_info("%s\n", cmd);
    system(cmd);
}

/**
 * @brief   合并Hex文件
 * @param   SrecCatPath SrecCat路径
 * @param   Hex1        hex文件1路径
 * @param   Hex2        hex文件2路径
 * @param   MergeHex    hex文件合并保存路径
 * @date    2024-08-22
 *
 */
void SrecCat_MergeHex(char *SrecCatPath, char *Hex1, char *Hex2, char *MergeHex)
{
    char cmd[256];
    sprintf(cmd, "%s %s -intel %s -intel -o %s -intel", SrecCatPath, Hex1, Hex2, MergeHex);
    LOG_info("%s\n", cmd);
    system(cmd);
}
